﻿<template>
    <div v-cloak class="flex-column" style="background-color: #F7F7F8; ">
        <component is="style" />
        <van-notice-bar color="#1989fa" background="#ecf9ff" left-icon="volume-o"  v-on:click="copy('pc/helperShare/726B656D-E6BA-430C-B878-E9771A743B04')">
            Bucket名称说明
        </van-notice-bar>
        <div class="flex-column-fill">
            <div class="text-center padding-top-8 padding-lr-8">
                <div class="bg-white padding-10">
                    <hxt-fileSelector ref="fileSelector" get-container="body">

                    </hxt-fileSelector>
                    <van-image round width="8rem" height="8rem"
                               :src="!!optor.imgUrl?optor.imgUrl:'https://ynz1901.oss-cn-shanghai.aliyuncs.com/main/bear.png'" v-on:click="fileSelect"></van-image>
                </div>
            </div>
            <van-cell-group inset title="账号信息">
                <van-cell title="账号" :value="optor.account"></van-cell>
                <van-cell title="密码" :value="optor.pwd"></van-cell>
            </van-cell-group>
            <van-cell-group inset title="扩展信息">
                <van-field label="Bucket名称" v-model="optor.bucketName" placeholder="设置后不可修改,请查看说明"
                           :border="true" :disabled="!!currentUser.bucketName"></van-field>
                <van-field label="姓名" v-model="optor.uiName" placeholder="请输入姓名"
                           :border="true"></van-field>
                <van-field label="邮箱" v-model="optor.email" :disabled="!!currentUser.email" placeholder="请输入邮箱"
                           :border="true"></van-field>
                <van-field label="备注" type="textarea" :autosize="{ maxHeight: 100, minHeight: 50 }"
                           v-model="optor.uiMark" placeholder="请输入备注"></van-field>
            </van-cell-group>
        </div>
        <div class="padding-15">
            <van-button round block type="info" v-on:click="submit">保 存</van-button>
        </div>
    </div>
</template>
<script>
    module = (function (hxt) {
        return {
            name: 'user',
            data: function () {
                return {
                    optor: hxt.store.optor,
                    currentUser: JSON.parse(JSON.stringify(hxt.store.optor)),
                    browser: hxt.wxBrowser(), // 1：手机微信；4：小程序

                };
            },
            computed: {

            },
            activated: function () {

            },
            watch: {

            },
            mounted: function () {
                var _this = this;
                _this.$parent.showHome = true;
            },
            methods: {
                fileSelect: function (e) {//吊起选文件
                    var _this = this;
                    _this.$refs.fileSelector.chooseFile({
                        type: 'image', success: function (res) {
                            _this.optor.imgUrl= URL.createObjectURL(res.file);
                        }
                    });
                },
                copy: function (url) {
                    var _this = this;
                    window.open(hxt.config.link + url);
                },
                submit: function () {
                    var _this = this, optor = _this.optor;
                    if (JSON.stringify(_this.optor) == JSON.stringify(_this.currentUser)) return hxt.msg("资料未更改");
                    if (!optor.bucketName) return hxt.error('请输入Bucket名称');
                    if (!(/^[A-Za-z]+$/.test(optor.bucketName))) return hxt.error('Bucket名称只能输入英文');
                    if (!hxt.isEmail(optor.email)) return hxt.error('无效的邮件地址');
                    optor.optType = 1;
                    optor.oiId = _this.optor.openId;
                    hxt.post({
                        url: hxt.config.link + "pc/getUserInfo",
                        data: optor,
                        ok: function (res) {
                            if (res.code != 0) return hxt.error('保存失败：' + res.errmsg);
                            hxt.success('保存成功');
                            _this.currentUser.uiName = _this.optor.uiName;
                            _this.currentUser.imgUrl = _this.optor.imgUrl;
                            _this.currentUser.uiMark = _this.optor.uiMark;
                            _this.currentUser.bucketName = _this.optor.bucketName;
                            _this.currentUser.email = _this.optor.email;
                        }
                    });
                    return
                    var save = function (data) {
                        hxt.post({
                            url: hxt.config.link + "pc/getUserInfo",
                            data: data,
                            ok: function (res) {
                                if (res.code != 0) return hxt.error('保存失败：' + res.errmsg);
                                hxt.success('保存成功');
                                _this.currentUser.uiName = _this.optor.uiName;
                                _this.currentUser.imgUrl = _this.optor.imgUrl;
                                _this.currentUser.uiMark = _this.optor.uiMark;
                                _this.currentUser.bucketName = _this.optor.bucketName;
                                _this.currentUser.email = _this.optor.email;
                            }
                        });
                    };
                    if (!optor.imgUrl.startsWith('https://')) {
                        hxt.uploadFile({
                            signUrl: hxt.config.link + 'pc/v3OssToken',
                            base64: optor.imgUrl,
                            file: null,
                            compress: false,
                            folder: 'avatar',
                            success: function (res) {
                                optor.imgUrl = res.data.url;
                                save(optor);
                            },
                            fail: function (err) {
                                hxt.unmask();
                                hxt.error('附件上传失败：' + err);
                            }
                        });
                        
                        return;
                    };
                    save(optor);
                },

            },
            components: {
                hxtFileSelector: function () { return hxt.staticComponent(@Html.Raw(this.vueComponent("~/Views/wx/Components/hxt.FileSelector.cshtml"))); }
            }
        };
    })(window.$jscript.fn);
</script>
<style>
</style>